package cn.dansj.service.Impl;

import cn.dansj.service.RoleMenuService;
import cn.dansj.entity.RoleMenu;
import cn.dansj.repository.RoleMenuRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoleMenuServiceImpl implements RoleMenuService {
    private final RoleMenuRepository roleMenuRepository;

    RoleMenuServiceImpl(RoleMenuRepository roleMenuRepository) {
        this.roleMenuRepository = roleMenuRepository;
    }

    public List<RoleMenu> getAll() {
        return roleMenuRepository.findAll();
    }

    public List<RoleMenu> getAllByRole(String role) {
        return roleMenuRepository.findAllByRole(role);
    }

    @Transactional
    public void deleteByRole(String role) {
        roleMenuRepository.deleteByRole(role);
    }

    public void save(List<RoleMenu> menu) {
        roleMenuRepository.saveAll(menu);
    }


}
